import java.sql.Array;
import java.util.Arrays;

public class Test {
    //超出时间限制
/*     public  void rotate(int[] nums, int k) {
        for (int i = 0; i < k; i++) {
            int tmp = nums[nums.length - 1];
            for (int j = nums.length - 1; j > 0 ; j--) {
                nums[j] = nums[j - 1];
            }
            nums[0] = tmp;
        }
    } */

    // 错误代码
/*     public static void rotate(int[] nums, int k) {
        int[] newArray = new int[nums.length];
        if(nums.length % 2 == 0){
            for (int i = 0,j = k; i <= k && j < newArray.length; i++,j++) {
                newArray[j] = nums[i];
            }
            for (int i = k ,j = 0; i <nums.length ; i++,j++) {
                newArray[j] = nums[i];
            }
        }

        else {
            for (int i = 0,j = k; i <= k && j < newArray.length; i++,j++) {
                newArray[j] = nums[i];
            }
            for (int i = k + 1 ,j = 0; i <nums.length ; i++,j++) {
                newArray[j] = nums[i];
            }
        }

        System.arraycopy(newArray,0,nums,0,nums.length);
    } */

    //拿下
   /*  public static void rotate(int[] nums, int k) {
        k = k % nums.length ;
        reverse(nums,0,nums.length - 1);
        reverse(nums,0,k - 1);
        reverse(nums,k,nums.length - 1);
    }
    
    public static void reverse(int[] nums,int start,int end){
        while(start < end){
            int tmp = nums[start];
            nums[start] = nums[end];
            nums[end] = tmp;
            start++;
            end--;
        }
    } */

    //拿下
    public static int missingNumber(int[] nums) {
        int sum1 = 0;
        int sum2 = 0;
        for (int i = 0; i < nums.length; i++) {
            sum1 += nums[i];
        }

        for (int i = 1; i < nums.length + 1; i++) {
            sum2 += i;
        }

        return sum2 - sum1;
    }


    public static void main(String[] args) {
        int[] nums = {1,3,2,5,0};
        int ret = missingNumber(nums);
        System.out.println(ret);



/*         int[] nums = {1,2,3,4,5,6,7};
        rotate(nums,3);
        String str = Arrays.toString(nums);
        System.out.println(str); */


    }
}
